function ParticleExplosionManager(cxt) {
	
	var particlePool = new Array();
	var particles = new Array();
	var context = cxt;
	var image = null;
	var MAX_POOL_SIZE = 100;
	
	this.setImage = function(img) {
		image = new Image();
		image.onload = this.imageLoaded;
		image.src = img;
	}
	
	function imageLoaded() {
	}
	
	this.draw = function() {
		for (var i=particles.length-1; i>= 0;i--) {
			particles[i].moves++;
			particles[i].x += particles[i].xunits;
			particles[i].y += particles[i].yunits + (particles[i].gravity * particles[i].moves);
			particles[i].life--;
			
			if (particles[i].life <= 0 ) {
				if (particlePool.length < MAX_POOL_SIZE) {
					particlePool.push(particles.splice(i,1));
				} else {
					particles.splice(i,1);
				}
			} else {
				context.globalAlpha = (particles[i].life)/(particles[i].maxLife);
				context.fillStyle = particles[i].color;
				if (image != null) {
					context.drawImage(image,particles[i].x,particles[i].y);
				} else {
					context.fillRect(particles[i].x,particles[i].y,particles[i].width , particles[i].height);
				}
					
				context.globalAlpha = 1;
			}
			
		}
	}
		
	this.createExplosion = function(x,y,color,number,width, height, spd, grav, lif) {
		for (var i =0;i < number;i++) {
			var angle = Math.floor(Math.random()*360);
			var speed = Math.floor(Math.random()*spd/2) + spd;	
			var life = Math.floor(Math.random()*lif)+lif/2;
			var radians = angle * Math.PI/ 180;
			var xunits = Math.cos(radians) * speed;
			var yunits = Math.sin(radians) * speed;
				
			if (particlePool.length > 0) {
				var tempParticle = particlePool.pop();
				tempParticle.x = x;
				tempParticle.y = y;
				tempParticle.xunits = xunits;
				tempParticle.yunits = yunits;
				tempParticle.life = life;
				tempParticle.color = color;
				tempParticle.width = width;
				tempParticle.height = height;
				tempParticle.gravity = grav;
				tempParticle.moves = 0;
				tempParticle.alpha = 1;
				tempParticle.maxLife = life;
				particles.push(tempParticle);
			} else {
				particles.push({x:x,y:y,xunits:xunits,yunits:yunits,life:life,color:color,width:width,height:height,gravity:grav,moves:0,alpha:1, maxLife:life});
			}	
	
		}
	}

}
